package com.spica.platform.base.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum IdempotencyRtnCodEnum implements IErrorCode {
    UN_KNOWN_IDEMPOTENCY_ERROR("BASE_IDEMPOTENCY_00000", "未知重发异常"),
    IDEMPOTENCY_DUPLICATE_ERROR("BASE_IDEMPOTENCY_00001", "重复提交"),
    ;
    private String rtnCod;
    private String rtnMsg;

    IdempotencyRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    };
    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(IdempotencyRtnCodEnum.values())
                .filter(idempotencyRtnCodEnum -> StringUtil.equals(idempotencyRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(IdempotencyRtnCodEnum.UN_KNOWN_IDEMPOTENCY_ERROR);
    }
}
